using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SQLite;
using Utils.WebFramework;
using DataAccess.Entitys;
using System.Text.RegularExpressions;
namespace DataAccess.SQLite
{
    class DataProvider
    {
        public DataProvider() 
        {

        }

        public void Connect() 
        {
            conn.ConnectionString = "Data Source=" + Framework.GetFramework().MainPath + Framework.GetFramework().ConnString;
            conn.Open();
        }

        public MetaUser GetUser(string uid) 
        {
            SQLiteCommand command = new SQLiteCommand();

            command.Connection  = conn;
            command.CommandText = "SELECT * FROM users WHERE uid=@uid";

            command.Parameters.Add("@uid", DbType.String).Value = uid;

            SQLiteDataReader dataReader = command.ExecuteReader();

            try
            {
                if (dataReader.Read())
                {
                    MetaUser metaUser = new MetaUser();

                    metaUser.uid  = dataReader.GetString(0);
                    metaUser.name = dataReader.GetString(1);

                    return metaUser;
                }
            }
            finally
            {
                dataReader.Close();
            }

            return null;
        }

        public void Close()
        {
            conn.Close();
        }

        private SQLiteConnection conn = new SQLiteConnection();
    }
}
